#include "setgcc.hh"
std::string gcc="gcc ";
std::string gpp="g++ ";
int changegcc(std::string cmd0,std::string v)                  //下命令可查看gcc可执行文件版本:strings -a program_name | grep -i gcc
{   std::string cmd="";
    cmd=gcc+cmd0;                                                      //证明替换后确实采用不同gcc版本编译
    int index;
    std::string target="gcc";
    std::string last,ft;
    std::string::size_type position;
    position=cmd.find(target);
    if (position == std::string::npos)
    {
         return -1;

    }
    else
    {    index=position+3;
         last=cmd.substr(index, cmd.length());
         ft=cmd.substr(0, position);
         std::system((ft+"gcc-"+v+last).c_str());
         std::cout<<"ok";                                     //测试用
         return 1;
    }
    return -1;

}
int changegpp(std::string cmd0,std::string v)
{   std::string cmd="";
    cmd=gpp+cmd0;     
    int index;
    std::string target="g++";
    std::string last,ft;
    std::string::size_type position;
    position=cmd.find(target);
    if (position == std::string::npos)
    {
         return -1;

    }
    else
    {    index=position+3;
         last=cmd.substr(index, cmd.length());
         ft=cmd.substr(0, position);
         std::system((ft+"g++-"+v+last).c_str());
         return 1;
    }
    return -1;

}
int installgcc(std::string v)
{
std::system(("sudo apt -y install gcc-"+v).c_str());
}
int installgpp(std::string v)
{
std::system(("sudo apt -y install g++-"+v).c_str());
}